package com.guoxin.thread.transport;

/**
 * 读出线程
 *
 * @author guoxin
 * @date 2019/6/28
 */
public class OutputThread extends Thread {

    private final Resource resource;

    public OutputThread(Resource resource) {
        this.resource = resource;
    }

    @Override
    public void run() {
        while (true) {
            synchronized (resource) {
                if (!resource.flag) {
                    try {
                        resource.wait();
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }
                System.out.println(resource.name + "--" + resource.six);
                resource.flag = false;
                resource.notify();
            }
        }
    }
}
